<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <style>
        body {
            background: url('https://cdn.pixabay.com/photo/2018/08/14/13/23/ocean-3605547_1280.jpg') no-repeat;
            background-size: 100% 160%;
        }

        #app {
            width: 24%;
            height: 465px;
            background-color: #00000060;
            margin: auto;
            margin-top: 10%;
            text-align: center;
            border-radius: 10px;
            padding: 50px 50px;
        }

        h2 {
            color: #ffffff90;
            margin-top: 5%;
        }

        #input-box {
            margin-top: 5%;
            line-height: 10px;
        }

        span {
            color: #fff;
        }

        input {
            border: 0;
            width: 60%;
            font-size: 15px;
            color: #fff;
            background: transparent;
            border-bottom: 2px solid #fff;
            padding: 5px 10px;
            outline: none;
            margin-top: 10px;
            line-height: 35px;
        }

        #regButton {
            margin-top: 30px;
            width: 60%;
            height: 30px;
            border-radius: 10px;
            border: 0;
            color: #fff;
            text-align: center;
            line-height: 30px;
            font-size: 15px;
            background-image: linear-gradient(to right, #30cfd0, #330867);
        }

        a {
            color: #b94648;
        }

        .el-upload{
            position: absolute;
            display: none;
            margin: -45px 143px;
        }

        .el-button{
            color: #fff;
            text-align: center;
            font-size: 15px;
        }

        #regbody{
            margin-left: 20px;
        }
    </style>
</head>

<body>
<div id="app">
    <h2>Register</h2>
    <div id="regbody">
        <div id="input-box">
            <input type="text" v-model="name" placeholder="请输入用户名">
        </div>
        <div class="input-box">
            <input type="password" v-model="pwd" placeholder="请输入密码">
        </div>
        <div class="input-box">
            <input type="password" v-model="repwd" placeholder="请输确定密码">
        </div>
        <div class="input-box">
            <input type="text" v-model="email" placeholder="请输入邮箱">
        </div>
        <div class="input-box">
            <input type="text" v-model="head" placeholder="请选择头像">
            <el-upload
                    ref="upload"
                    action="#"
                    :on-success="handleSuccess"
                    :on-error="handleError">
                <el-button style="background-image: linear-gradient(to right, #30cfd0, #330867);border: none" slot="trigger" size="small" type="primary">选择文件</el-button>
            </el-upload>
        </div>

    </div>

    <button id="regButton" @click="reg">注册</button><br>
</div>

<script src="http://47.106.66.89:8080/js/vue.min.js"></script>
<script src="http://47.106.66.89:8080/js/axios.min.js"></script>
<link href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
<script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>

<script>
    let app = new Vue({
        el: '#app',
        data:{
            name: '',
            pwd: '',
            repwd:'',
            email:'',
            head:''
        },
        created() {

        },
        methods: {
            reg(){
                let p = new URLSearchParams();
                p.append("name",this.name);
                p.append("pwd",this.pwd);
                p.append("repwd",this.repwd);
                p.append("email",this.email);
                //只能选择D盘目录下的图片
                if (this.head == ''){
                    p.append("head",this.head);
                }else{
                    p.append("head","D:\\"+this.head);
                }
                axios.post("reg",p).then(resp=>{
                    if (resp.data.code == 1 ){
                        this.$message(resp.data.msg);
                        location.href = "login.html";
                    }else{
                        this.$alert(resp.data.msg);
                    }
                });
            },
            submitUpload() {
                this.$refs.upload.submit();
            },
            handleSuccess(response, file, fileList) {
               this.head = file.name;
            },
            handleError(err, file, fileList) {
                console.error('Error uploading file:', err);
            }
        }
    });

</script>
</body>
</html>
